import React from "react";

class BasePureComponent<P = {}, S = {}, SS = any> extends React.PureComponent<P, S, SS> {

  constructor(props: P) {
    super(props);
    // this.bindAllMethod();
  }

  componentWillUnmount() {
    this.setState = () => {
      console.log("setState called after unmount");
    };
  }

  setAllState(states: any[]) {
    const self = this;
    states = states.reverse();
    return new Promise((resolve, reject) => {
      self._setAllState(resolve, states);
    });
  }

  private _setAllState(resolve: any, states: any[]) {
    const self = this;
    self.setState(states.pop(), () => {
      setTimeout(() => {
        if (states.length === 0) {
          resolve();
          return;
        }
        self._setAllState(resolve, states);
      }, 300);
    });
  }

  // private bindAllMethod() {
  //   for (const key of Object.keys(this.prototype)) {
  //     if (key.endsWith("_bind") ){
  //       if (typeof this[key] === "function") {
  //         this[key] = this[key].bind(this);
  //       }
  //     }
  //   }
  // }
}

export default BasePureComponent;
